﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// 角色基础属性类，从这里面直接取数值即可
/// </summary>
public class PlayerStatus : MonoBehaviour
{
    PlayerController playerController;

    public float maxStamina = 100f;
    public float speed = 10f;
    public Status stamina;
    //每次体力扣除时，扣除的具体数值
    public float staminaLoseRatio = 5f;
    public float staminaRecoverRatio = 5f;
    public float collectRange = 10f;
    public float collectTime = 1f;

    float lastReduceTime = 0f;
    //多少秒扣一次体力
    public float reduceCooldown = 0.5f;

    public bool isCostingStamina = true;
    

    //角色处于holding状态的时候，要持续扣体力
    public void reduceStamina()
    {
        if(Time.time - lastReduceTime > reduceCooldown)
        {
            //stamina.PrintStatus();
            stamina.Modify(-staminaLoseRatio);
            int borderCheckCode = stamina.BorderCheck();
            //发现体力扣光了
            if (borderCheckCode == 1)
            {
                playerController.DropCoin();
            }
            lastReduceTime = Time.time;
        }
    }

    public void recoverStamina()
    {
        if (Time.time - lastReduceTime > reduceCooldown)
        {
            //stamina.PrintStatus();
            int borderCheckCode = stamina.BorderCheck();
            if (borderCheckCode == 2)
                return;
            stamina.Modify(staminaRecoverRatio);
            lastReduceTime = Time.time;
        }
    }



    // Start is called before the first frame update
    void Start()
    {
        stamina = new Status(maxStamina);
        playerController = GetComponent<PlayerController>();
    }

    // Update is called once per frame
    void Update()
    {
        if (playerController.holdingCoin)
        {
            if (isCostingStamina)
                reduceStamina();
        }
        else
        {
            recoverStamina();
        }
    }
}
